package com.example.demo.common.util; /**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 * <p>
 * https://www.renren.io
 * <p>
 * 版权所有，侵权必究！
 */


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.io.Serializable;
import java.util.List;

/**
 * 分页工具类
 *
 * @author Mark sunlightcs@gmail.com
 */
public class PageUtils<T> implements Serializable {
    private static final long serialVersionUID = 1L;
       /**
     * 每页记录数
     */
    private int pageSize;


    /**
     * 总页数
     */
    private int total;


    /**
     * 当前页数
     */
    private int pageNum;
    /**
     * 列表数据
     */
    private List<?> list;

    static PageHelper pageHelper;


    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }


    public int getPageNum() {
        return pageNum;
    }

    static public void startPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }



    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }


    public List<?> getList() {
        return list;
    }

    public void setList(List<?> list) {
        this.list = list;
    }



/*	public PageUtils(List<?> list, int totalCount, int pageSize, int pageNum) {
		this.list = list;
		this.totalCount = totalCount;
		this.pageSize = pageSize;
		this.pageNum = pageNum;
		this.totalPage = (int)Math.ceil((double)totalCount/pageSize);
	}
	*/

    /**
     * 分页
     *//*
	public PageUtils(IPage<?> page) {
		this.list = page.getRecords();
		this.totalCount = (int)page.getTotal();
		this.pageSize = (int)page.getSize();
		this.pageNum = (int)page.getCurrent();
		this.totalPage = (int)page.getPages();
	}*/
    public PageUtils(List<?> lists) {
        PageInfo<?> pages = new PageInfo(lists);
        this.list = pages.getList();
//        this.totalCount = (int) pages.getTotal();
        this.pageSize = (int) pages.getSize();
        this.pageNum = (int) pages.getPageNum();
        this.total = (int) pages.getPages();
    }
}
